// ignore_for_file: prefer_const_constructors

import 'package:favourcate/core/extension/int_fit_ext.dart';
import 'package:favourcate/core/viewmodel/filter_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class GLFilterContent extends StatelessWidget {
  const GLFilterContent({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        buildChoiceTitle(context),
        buildChoiceSelect(context) 
      ],
    );
  }

  Widget buildChoiceTitle(context) {
    return Container(
      padding: EdgeInsets.all(10.px),
      alignment: Alignment.center,
      child: Text(
        '展示你的选择',
        style: Theme.of(context).textTheme.headline3!.copyWith(
          fontWeight: FontWeight.bold
        ),
      ),
    );
  }

  Widget buildChoiceSelect(context) {
    return Expanded(
      child: Consumer<GLFilterViewModel>(
        builder: (ctx, filterStore, child) {
          return ListView(
            children: [
              buildListTile('五谷蛋白', '展示五谷蛋白食物', filterStore.isGlutenFree, (value) {
                filterStore.isGlutenFree = true;
              }),
              buildListTile('不含乳糖', '展示不含乳糖食物', filterStore.isLactoseFree, (value) {
                filterStore.isLactoseFree = true;
              }),
              buildListTile('普通食素者', '展示普通食素者相关食物', filterStore.isVegetarial, (value) {
                filterStore.isVegetarial  = true;
              }),
              buildListTile('严格食素者', '展示严格食素者相关食物', filterStore.isVegan, (value) {
                filterStore.isVegan = true;
              }),
            ],
          );
        },
      ) 
    );
  }

  Widget buildListTile(String title, String subTitle, bool value, onChange) {
    return ListTile(
      title: Text(title),
      subtitle: Text(subTitle),
       trailing: Switch(
        value: value,
        onChanged: onChange
      ),
    );
  }
}